As a conventional image coding method, a predictive encoding-based method has been proposed. The predictive coding method comprises a sequence conversion unit which converts image data into a prediction error by predictive transform, and an entropy encoding unit which converts the prediction error output from the sequence conversion unit into encoded data of less redundancy.
As an example of a scheme using predictive encoding, an international standard JPEG-LS (ITU-T T.87|ISO/IEC 14495-1) is known.
JPEG (ITU-T T.81|ISO/IEC 10918-1) defines a lossless coding scheme in which an independent function is based on predictive coding. This lossless coding scheme will be called a JPEG lossless coding mode. In the JPEG lossless coding mode, seven prediction equations are defined as a method of predicting the value of a pixel of interest (target pixel) from neighboring pixels, and the prediction method can be selected in accordance with an image.
FIG. 2 is a block diagram showing a conventional image processing apparatus. FIG. 2 shows an example of the apparatus which losslessly compresses an image in the above-described JPEG lossless coding mode. In FIG. 2, reference numeral 201 denotes a buffer; 202, a component value prediction unit; 203, a subtracter; 204, a Huffman table memory; 205, a prediction error encoding unit; 209, a code stream formation unit; and 206, 207, and 208, signal lines.
The Huffman table memory 204 stores a Huffman table for use in the prediction error encoding unit 205. Assume that the Huffman table memory 204 stores a Huffman table shown in FIG. 6.
The flow of a process when a conventional image processing apparatus encodes an RGB color image whose components each are expressed by 8 bits will be explained with reference to FIG. 2.
A prediction selection signal m for selecting a prediction method for use in the component value prediction unit 202 is input from the signal line 208. The prediction selection signal m takes an integer value of 0 to 7, and the respective values correspond to different prediction equations. When one image is encoded, the prediction selection signal m does not change and is fixed. FIG. 4 shows the correspondence between the prediction equation for use and the prediction selection signal m. When the prediction selection signal m is 0, no prediction equation is defined. This means that each component is directly encoded without performing any predictive transform. Symbols “p”, “a”, “b”, and “c” in FIG. 4 will be explained below.
Image data are sequentially input from the signal line 206. The image data input order is the raster scan order, and component data of each pixel are input in the order of R, G, and B. The R, G, and B components are defined as component numbers of 0, 1, and 2, respectively. The upper left corner of an image is defined as coordinates (0,0), and the value of the component number C of a pixel at the horizontal pixel position x and vertical pixel position y is represented by P(x,y,C). For example, when a pixel at the position (x,y)=(3,4) has (R,G,B)=(255,128,0), P(3,4,0)=255, P(3,4,1)=128, and P(3,4,2)=0.
The buffer 201 has a capacity for storing image data of two lines that are input from the signal line 206.
When the component value x of the pixel of interest=P(x,y,C), the component value prediction unit 202 extracts, from the buffer 201, the value “a” of the same component of an immediately preceding pixel=P(x−1,y,C), the value “b” of the same component of a pixel before one line=P(x,y−1,C), and the value “c” of the same component of an obliquely upper left pixel=P(x−1,y−1,C). The component value prediction unit 202 generates a predicted value “p” in accordance with the prediction scheme selection signal m. FIG. 3 shows the positional relationship between “a”, “b”, “c”, and the component value x of the pixel of interest. Note that when “a”, “b”, and “c” are outside an image, they are set to 0.
The subtracter 203 calculates the difference value between the predicted value p and the component value x to be encoded, and outputs it as a prediction error e.
The prediction error encoding unit 205 classifies prediction errors e input from the subtracter 203 into a plurality of groups, and generates a group number SSSS and overhead bits of a bit length defined for each group. FIG. 5 shows the relationship between the prediction error e and the group number SSSS. The overhead bits are information for specifying a prediction error in the group, and the bit length is given by the group number SSSS. Note that the bit length is exceptionally 0 for SSSS=16 (when the precision of each component is 8 bits, SSSS=16 is not generated). If the prediction error e is positive, the lower SSSS bits of the prediction error e become overhead bits; if the prediction error e is negative, the lower SSSS bits of e−1 become overhead bits. The MSB (Most Significant Bit) of overhead bits is 1 for a positive prediction error e and 0 for a negative prediction error e. In an encoding process, encoded data corresponding to the group number SSSS is output by looking up the Huffman table stored in the Huffman table memory 204. When SSSS is neither 0 nor 16, overhead bits of a bit length defied by the group number are output.
The code stream formation unit 209 forms a code stream of a format complying with the JPEG standard from encoded data output from the prediction error encoding unit 205, and additional information (e.g., the prediction selection signal m input via the signal line 208, the numbers of horizontal and vertical pixels of an image, the number of components which form a pixel, and the precision of each component). The code stream formation unit 209 outputs the code stream to the signal line 207.
In addition to predictive encoding, run-length encoding is also known. According to run-length encoding, when a pixel of interest matches a previously encoded pixel, information representing the number of matched pixels is encoded. This encoding has high encoding efficiency when identical pixels run in an image.
The purpose of encoding is to reduce the data amount of an original image, and that of lossless coding is to generate a code which can be completely decoded into an original image. When one image is losslessly encoded, it is more desirable to locally use the predictive encoding technique and run-length encoding technique than to apply only one of them.
However, a method of efficiently encoding data while these encoding techniques are switched and used has not been established.